import React from 'react'
import type { RenderWidgetBaseProps } from './interface'
import { registry } from './registry'
type RenderWidgetProps = {
  role: string
  children?: React.ReactNode
} & Omit<RenderWidgetBaseProps, 'config'>

export const RenderWidget: React.FC<RenderWidgetProps> = ({ role, children, ...restProps }) => {
  const { render, ...config } = registry[role] || registry.default
  return (
    <span {...restProps} className="md-html-node">
      {React.createElement(render, { ...restProps, config }, children)}
    </span>
  )
}
